/**
 * 部门js
 */
var chgLog = {
	key:"ChgLog_key_",
	curPage : 1,
	pageSize : 10,
	dataCache : null,

	startEvent : function() {
		// 按回车键登录事件
		document.onkeydown = function(e) {
			var ev = document.all ? window.event : e;
			if (ev.keyCode == 13) {
				chgLog.curPage = 1;
				chgLog.setPageChange(null);
				chgLog.search();
			}
		};
	},
	
	bindEvent : function() {
		// 查询
		$('#searchData').click(function() {
			chgLog.curPage = 1;
			chgLog.setPageChange(null);
			chgLog.search();
		});
	},

	// 设置分页
	setPageChange : function(delCurPage) {
		var url = 'mgr/SysChgLogCtrl/getLogList';
		var params = jsUtils.serializeJson($('#searchModForm'));
		params.curPage = chgLog.curPage;
		params.pageSize = 999999;
		if (typeof (pageIdx) != "undefined") {
			chgLog.curPage = pageIdx;
		}
		 
		
		var cb = function(data) {
			if (data.resultCode == 200) {
				var totalCount = data.size;
				var pageTotal = (totalCount / chgLog.pageSize > 0) ? Math
						.ceil(totalCount / chgLog.pageSize) : 1;
						
				pageHelper.init(pageTotal, totalCount, chgLog.search,
						delCurPage); // 翻页事件
			}else{
				alert(data.msg);
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},

	// 查询交易记录
	search : function(pageIdx) {

		if (typeof(pageIdx) != "undefined"){
			chgLog.curPage=pageIdx;
		}

		var url = 'mgr/SysChgLogCtrl/getLogList';
		var params = jsUtils.serializeJson($('#searchModForm'));
		params.curPage = chgLog.curPage;
		params.pageSize = chgLog.pageSize;
		
		var cb = function(data) {
			$('#tableList tbody').empty();
			var tr = '';

			if (data.result != null && data.result.length > 0) {
				for (var i = 0; i < data.result.length; i++) {
					
					
					var singleObj = data.result[i];
					
					localStorage.setItem( chgLog.key + singleObj.id, JSON.stringify(singleObj));
					
					tr += '<tr><td>'
							+'<input type="hidden" name="id" value="' + singleObj.id+ '"/>'
							+'<input type="hidden" name="type" value="' + singleObj.type+ '"/>'
							+ (i + 1)
							+ '</td><td>'
							+  jsUtils.getDictionaryTxtByType("logType", singleObj.type)
							+ '</td><td>'
							+ singleObj.chgDesc
							+ '</td><td>'
							+ singleObj.recordId
							+ '</td><td>'
							+ (singleObj.userName!=null?singleObj.userName:"")
							+ '</td><td>'
							+ singleObj.actUserName
							+ '</td><td>'
							+ getSmpFormatDateByLong(singleObj.cts,true)
							+ '</td><td>'
							+'<a type="button" name="chgLog_99" class="btn btn-primary btn-xs lookData" style="margin-left: 5px;display:none;">'
							+'<i class="fa fa-reorder"></i> 查看 </a>'
							+ '</td></tr>';
				}
			} else {
				tr = '<tr><td colspan="6" style="text-align: center;color: red;">暂无数据</td></tr>';
			}
			$('#tableList tbody').html(tr);
			chgLog.bindEventOtherBtn();
			jsUtils.controlFunctionBtn();
		};

		sendApiNoLoad(url, params, cb, 'POST');
	},

	bindEventOtherBtn : function() {
		$('.lookData').unbind();
		$('.lookData').on(
				'click',
				function() {
					 
					var thisObj = $(this);
					var id = thisObj.parent().parent().find('input[name="id"]')
							.eq(0).val();
					var type = thisObj.parent().parent().find('input[name="type"]')
					.eq(0).val();
					 
					var key =  chgLog.key + id;
					var record = eval('(' + localStorage.getItem(key) + ')');
					
					var beforeImage = record.beforeImg;
					
					var afterImage = record.afterImg;
				
				
					art.dialog.data('lokId', id);
					
					if(type==1||type==2){
						var path = APP_ADDRESS
						+ 'mgr/sysMgr/chgLog/chgLogUserLook.jsp';
						art.dialog.open(path, {
							title : '对比用户信息修改内容',
							width : 600,
							height : 800,
							cancel : true
						});
						
					}else if(type==3){
						var path = APP_ADDRESS
						+ 'mgr/sysMgr/chgLog/chgLogOrderLook.jsp';
						art.dialog.open(path, {
							title : '对比订单修改内容',
							width : 600,
							height : 200,
							cancel : true
						});
					}else if(type == 5){
						var path = APP_ADDRESS
								+ 'mgr/sysMgr/chgLog/chgLogProdPayBackLook.jsp';
						art.dialog.open(path, {
							title : '对比产品回款修改内容',
							width : 600,
							height : 200,
							cancel : true
						});
					}else if(type == 6){
						var path = APP_ADDRESS
								+ 'mgr/sysMgr/chgLog/chgLogOrgLook.jsp';
						art.dialog.open(path, {
							title : '对比组织架构修改内容',
							width : 600,
							height : 400,
							cancel : true
						});
					}else if(type == 7){
                        var path = APP_ADDRESS
                            + 'mgr/sysMgr/chgLog/chgLogSafety.jsp';
                        art.dialog.open(path, {
                            title : '对比安全设置修改内容',
                            width : 600,
                            height : 400,
                            cancel : true
                        });
                    }else if(type == 10){
						var path = APP_ADDRESS
								+ 'mgr/sysMgr/chgLog/chgLogProdPayBackPhoneLook.jsp';
						art.dialog.open(path, {
							title : '对比回款划拨授权码接收设置修改内容',
							width : 600,
							height : 200,
							cancel : true
						});
					}
					
				});
	},

	init : function() {
		chgLog.startEvent();
		chgLog.bindEvent();
		chgLog.search();
		chgLog.setPageChange();
		jsUtils.controlFunctionBtn();
	}
};

$(document).ready(function() {
	chgLog.init();
});

//提供给外部刷新调用
function refashData() {
	chgLog.setPageChange(null);
	chgLog.search();
}

 


